package com.whj.apidriver.controller;

import com.whj.apidriver.service.VerificationCodeService;
import com.whj.internalcommon.dto.ResponseResult;
import com.whj.internalcommon.request.VerificationCodeDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Auther: wanghaijun
 * @Date: 2023/1/14 - 01 - 14 - 15:01 
 * @Description: com.whj.apidriver.controller
 */

@RestController
@Slf4j
public class VerificationCodeController {

    @Autowired
    private VerificationCodeService verificationCodeService;

    /**
     * 通过手机号来发送验证码接口
     *
     * @param verificationCodeDTO
     * @return
     */
    @PostMapping("/verification-code")
    public ResponseResult verificationCode(@RequestBody VerificationCodeDTO verificationCodeDTO){

        String driverPhone = verificationCodeDTO.getDriverPhone();
        log.info("司机的手机号："+driverPhone);
        return verificationCodeService.checkAndSentVerificationCode(driverPhone);
    }

    /**
     * 校验验证码
     * @param verificationCodeDTO
     * @return
     */
    @PostMapping("/verification-code-check")
    public ResponseResult checkVerificationCode(@RequestBody VerificationCodeDTO verificationCodeDTO){

        String driverPhone = verificationCodeDTO.getDriverPhone();
        String verificationCode = verificationCodeDTO.getVerificationCode();
        System.out.println("driverPhone = " + driverPhone);
        System.out.println("verificationCode = " + verificationCode);
        return verificationCodeService.checkCode(driverPhone,verificationCode);
    }
}
